package com.snailhd.utils;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author hd
 * @description
 * @date 2019-10-12 12:27
 */
public class ThreadPoolUtil {

    private static int nThreads= 10;

    private static ExecutorService executor = null;

    public static void execute(Runnable r){
        init();
        executor.execute(r);
    }

    public static void init(){
        if(executor==null){
            synchronized (ExecutorService.class){
                if(executor==null){
                    executor = Executors.newFixedThreadPool(nThreads);
                }
            }
        }
    }
}
